package main;

import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import static com.mongodb.client.model.Filters.eq;

import com.mongodb.client.MongoCursor;
import main.database.DatabaseMan;
import org.bson.Document;

public class CommentHelper {
    public static String getLastCommentTime(String uuid) {
        MongoCollection<Document> collection = DatabaseMan.Instance().GetCollection(GlobalConfig.collectionNameOfCommentToArticle);
        Document sortMethod = new Document("createtime", -1);
        FindIterable<Document> findIterable = collection.find(eq("userid", uuid)).sort(sortMethod).limit(1);
        MongoCursor<Document> cursor = findIterable.iterator();

        String time = "";
        if (cursor.hasNext()) {
            time = cursor.next().get("createtime").toString();
        }

        cursor.close();

        return time;
    }
}
